package com.sduept.nwld.dataserver.util;

import com.sduept.nwld.dataserver.sourceinfo.transform.impl.SubString;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class TransformFuncUtil {	
	public static Object generateTransfromInfo(Object sourceInfo,String funcName,String _params){
		Object targetInfo=null;
		if(funcName!=null && !"".equals(funcName)){
			if(_params!=null){
				if("substring".equals(funcName) ){
					String[] myparams=_params.split(",");
					if(myparams.length==2){
						SubString subString=new SubString();
						int beginIndex=Integer.parseInt(myparams[0]);
						int endIndex=sourceInfo.toString().indexOf(myparams[1])+1;
						Map<String,Object> params=subString.getParams();
						params.put("sourceInfo", sourceInfo.toString());
						params.put("beginIndex",beginIndex );
						params.put("endIndex", endIndex);					
						targetInfo=subString.apply(params);
					}else if(myparams.length==1){
						SubString subString=new SubString();
						int beginIndex=sourceInfo.toString().indexOf(myparams[0])+1;
						Map<String,Object> params=subString.getParams();
						params.put("sourceInfo", sourceInfo.toString());
						params.put("beginIndex",beginIndex );
						targetInfo=subString.apply(params);
					}
				}
			}
		}
		return targetInfo;
	}
		
	public static void main(String[] args){
		String str="500kV池塘站";
		str=str.substring(str.toString().indexOf('V')+1);
		log.info(str);
	}

}
